﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraCharts;
using DevExpress.XtraEditors;

namespace Client
{
    public partial class FrmMarket : BaseChildForm
    {
        public FrmMarket()
        {
            InitializeComponent();
            dateSpan.StartDateEdit.Properties.DisplayFormat.FormatString = "yyyy-MM";
            dateSpan.StartDateEdit.Properties.DisplayFormat.FormatType = FormatType.DateTime;
            dateSpan.EndDateEdit.Properties.DisplayFormat.FormatString = "yyyy-MM";
            dateSpan.EndDateEdit.Properties.DisplayFormat.FormatType = FormatType.DateTime;

            dateSpan.StartDateEdit.DateTime = DateTime.Now.AddMonths(-6).Date;
            dateSpan.EndDateEdit.DateTime = DateTime.Now.Date;
        }
        public override void BindData()
        {
            DrawChart();
        }
        private void FrmBusiness_Load(object sender, EventArgs e)
        {
            DrawChart();
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            DrawChart();
        }

        private void DrawChart()
        {
            if (this.dateSpan.StartDateEdit.EditValue == null||this.dateSpan.EndDateEdit.EditValue== null)
            {
                GlobalInfo.MsgBoxShowInfo("请选择统计日期段!");
                return;
            }

            DateTime startDate = dateSpan.StartDateEdit.DateTime;
            DateTime endDate = dateSpan.EndDateEdit.DateTime;
            QunYing.BLL.OrderInfo info = new QunYing.BLL.OrderInfo();
            DataTable dt = info.QueryTotalMarket(GlobalInfo.UserLoginInfo.用户ID, startDate, endDate);

            chartControl1.BeginInit();
            chartControl1.Series.Clear();
            Series series1 = new Series("series1", ViewType.Bar);
            series1.LegendText = "销售额";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                series1.Points.Add(new SeriesPoint(dt.Rows[i]["月份"], dt.Rows[i]["销售额"]));
            }
            chartControl1.Series.Add(series1);
            chartControl1.EndInit();
        }
    }
}